// yarn add events  事件总线的概述  有跨组件之间的事件传递
import React, { PureComponent } from "react";

import { EventEmitter } from "events";

const eventBus = new EventEmitter(); //创建一个实例 (可以抽离的)

class Son extends PureComponent {
  render() {
    return (
      <div>
        123~
        <button
          onClick={(e) => {
            this.handleClick();
          }}
        >
          btn
        </button>
      </div>
    );
  }
  handleClick() {
    eventBus.emit("biubiuClick", "哦豁!!", 123445556);
  }
}

class index extends PureComponent {
  componentDidMount() {
    eventBus.addListener("biubiuClick", this.headerClick);
  }
  componentWillUnmount() {
    eventBus.removeListener("biubiuClick", this.headerClick);
  }
  render() {
    return (
      <div>
        <Son></Son>
      </div>
    );
  }
  headerClick(a, b) {
    console.log("a,b: ", a, b);
    console.log("触发!");
  }
}

export default index;
